package com.cheung.leetcode.dp;

import org.junit.jupiter.api.Test;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.dp
 * @Author :  cheungming
 * @CreateTime : 2024-06-12 09:44:09
 * @Description : 二叉树的组合数
 * @Version : 1.0
 */
public class Code96Test {

    public int numTrees(int n) {
        int[] dp = new int[n + 1];
        dp[0] = 1;
        for (int i = 1; i <= n; i++) {
            // 遍历所有可能的根节点，根节点的左子树有j-1个节点，右子树有i-j个节点
            for (int j = 1; j <= i; j++) {
                dp[i] += dp[j - 1] * dp[i - j];
            }
        }
        return dp[n];
    }

    @Test
    public void test1() {
        assert numTrees(3) == 5;
    }

    @Test
    public void test2() {
        assert numTrees(1) == 1;
    }

}
